home *** CD-ROM | disk | FTP | other *** search
/ Chip 2011 November / CHIP_2011_11.iso / Programy / Inne / Gry / Carnage_Contest / scripts / CC Original / weapons / Blow Gun.lua < prev    next >
Text File  |  2010-08-31  |  5KB  |  156 lines

  1. --------------------------------------------------------------------------------
  2. -- Weapon Blow Gun + Projectile Dart
  3. -- Original Carnage Contest Weapon
  4. -- Script by DC, September 2009, www.UnrealSoftware.de
  5. --------------------------------------------------------------------------------
  6.  
  7. -- Setup Tables
  8. if cc==nil then cc={} end
  9. cc.blowgun={}
  10. cc.blowgun.dart={}
  11.  
  12. -- Load & Prepare Ressources
  13. cc.blowgun.gfx_wpn=loadgfx("weapons/blowgun.bmp")                -- Weapon Image
  14. sethandle(cc.blowgun.gfx_wpn,4,14)
  15. cc.blowgun.gfx_icon=loadgfx("weapons/blowgunicon.bmp")            -- Weapon Icon
  16. setmidhandle(cc.blowgun.gfx_icon)
  17. cc.blowgun.gfx_pro=loadgfx("weapons/dart.bmp")                    -- Projectile Image
  18. setmidhandle(cc.blowgun.gfx_pro)
  19. cc.blowgun.sfx_attack=loadsfx("arrow_shoot.ogg")                -- Attack Sound
  20. cc.blowgun.sfx_impact=loadsfx("arrow_impact.ogg")                -- Impact Sound
  21.  
  22. --------------------------------------------------------------------------------
  23. -- Weapon: Blow Gun
  24. --------------------------------------------------------------------------------
  25.  
  26. cc.blowgun.id=addweapon("cc.blowgun","Blow Gun (Tranquilizer)",cc.blowgun.gfx_icon,0)    -- Add Weapon (0 uses)
  27. cc.blowgun.ammo=1                                                -- 1 Dart
  28.  
  29. function cc.blowgun.draw()                                        -- Draw
  30.     setblend(blend_alpha)
  31.     setalpha(1)
  32.     setcolor(255,255,255)
  33.     drawinhand(cc.blowgun.gfx_wpn,4,-4)
  34.     -- HUD Crosshair
  35.     if cc.blowgun.ammo-weapon_shots>0 then
  36.         hudcrosshair(4,-1)
  37.     end
  38. end
  39.  
  40. function cc.blowgun.attack(attack)                                -- Attack
  41.     -- Decrement timer
  42.     if weapon_timer>0 then
  43.         weapon_timer=weapon_timer-1
  44.     end
  45.     -- Attack
  46.     if weapon_shots<cc.blowgun.ammo and weapon_timer<=0 and attack==1 then
  47.         -- No more weapon switching!
  48.         useweapon(0)
  49.         -- Reset Timer
  50.         weapon_timer=25
  51.         -- Attack
  52.         playsound(cc.blowgun.sfx_attack)
  53.         weapon_shots=weapon_shots+1
  54.         id=createprojectile(cc.blowgun.dart.id)
  55.         projectiles[id]={}
  56.         -- Ignore collision with current player at beginning
  57.         projectiles[id].ignore=playercurrent()
  58.         -- Set initial position of projectile
  59.         projectiles[id].x=getplayerx(0)+(4*getplayerdirection(0))-math.sin(math.rad(getplayerrotation(0)))*10.0
  60.         projectiles[id].y=getplayery(0)-4+math.cos(math.rad(getplayerrotation(0)))*10.0
  61.         -- Set speed of projectile
  62.         projectiles[id].sx=math.sin(math.rad(getplayerrotation(0)))*14.0
  63.         projectiles[id].sy=-math.cos(math.rad(getplayerrotation(0)))*14.0
  64.         -- Initial movement
  65.         projectiles[id].x=projectiles[id].x-projectiles[id].sx*0.3
  66.         projectiles[id].y=projectiles[id].y-projectiles[id].sy*0.3
  67.         for i=1,1,1 do
  68.             if cc.blowgun.dart.move(id)==1 then
  69.                 break
  70.             end
  71.         end
  72.         -- Effects
  73.         recoil(3)
  74.         -- End Turn
  75.         if (weapon_shots>=cc.blowgun.ammo) then
  76.             endturn()
  77.         end
  78.     end
  79. end
  80.  
  81. --------------------------------------------------------------------------------
  82. -- Projectile: Dart
  83. --------------------------------------------------------------------------------
  84.  
  85. cc.blowgun.dart.id=addprojectile("cc.blowgun.dart")        -- Add Projectile
  86.  
  87. function cc.blowgun.dart.draw(id)                        -- Draw
  88.     -- Setup draw mode
  89.     setblend(blend_alpha)
  90.     setalpha(1)
  91.     setcolor(255,255,255)
  92.     setscale(1,1)
  93.     -- Calculate projectile rotation
  94.     setrotation(math.deg(math.atan2(projectiles[id].sx,-projectiles[id].sy)))
  95.     -- Draw projectile
  96.     drawimage(cc.blowgun.gfx_pro,projectiles[id].x,projectiles[id].y)
  97.     -- Draw arrow if out of Screen
  98.     outofscreenarrow(projectiles[id].x,projectiles[id].y)
  99. end
  100.  
  101. function cc.blowgun.dart.update(id)                        -- Update
  102.     -- Wind + Gravity influence on speed
  103.     projectiles[id].sx=projectiles[id].sx+getwind()*0.1
  104.     projectiles[id].sy=projectiles[id].sy+getgravity()*1.5
  105.     -- Move
  106.     cc.blowgun.dart.move(id)
  107. end
  108.  
  109. function cc.blowgun.dart.move(id)
  110.     rot=math.deg(math.atan2(projectiles[id].sx,-projectiles[id].sy))
  111.     -- Move (in substep loop for optimal collision precision)
  112.     msubt=math.ceil(math.max(math.abs(projectiles[id].sx),math.abs(projectiles[id].sy))/2)
  113.     msubx=projectiles[id].sx/msubt
  114.     msuby=projectiles[id].sy/msubt
  115.     for i=1,msubt,1 do
  116.         projectiles[id].x=projectiles[id].x+msubx
  117.         projectiles[id].y=projectiles[id].y+msuby        
  118.         -- Collision
  119.         if collision(col2x2,projectiles[id].x+math.sin(math.rad(rot))*4,projectiles[id].y-math.cos(math.rad(rot))*4)==1 then
  120.             if terraincollision()==1 or objectcollision()>0 or playercollision()~=projectiles[id].ignore then
  121.                 if playercollision()~=0 then
  122.                     -- Sleep!
  123.                     playsound(sfx_splatter3)
  124.                     playerstate(playercollision(),state_sleeping,1)
  125.                 elseif terraincollision()==1 then
  126.                     -- Draw dart in terrain
  127.                     terrainimage(cc.blowgun.gfx_pro,projectiles[id].x,projectiles[id].y,0,rot)
  128.                 end
  129.                 -- Effects
  130.                 playsound(cc.blowgun.sfx_impact)
  131.                 particle(p_smoke,projectiles[id].x+math.sin(math.rad(rot))*4,projectiles[id].y-math.cos(math.rad(rot))*4)
  132.                 particlefadealpha(0.006)
  133.                 -- Free projectile
  134.                 freeprojectile(id)
  135.                 return 1
  136.             end
  137.         else
  138.             projectiles[id].ignore=0
  139.         end
  140.         -- Water
  141.         if (projectiles[id].y)>getwatery()+5 then
  142.             -- Effects
  143.             particle(p_waterhit,projectiles[id].x,projectiles[id].y)
  144.             if math.random(1,2)==1 then
  145.                 playsound(sfx_hitwater2)
  146.             else
  147.                 playsound(sfx_hitwater3)
  148.             end
  149.             -- Free projectile
  150.             freeprojectile(id)
  151.             return 1
  152.         end
  153.     end
  154.     -- Scroll to projectile
  155.     scroll(projectiles[id].x,projectiles[id].y)
  156. end